articles

Home / DeveloperSection / Articles / Explain the SQL Server backups and their types

Explain the SQL Server backups and their types

Explain the SQL Server backups and their types

Ashutosh Kumar Verma 188 04-Jul-2024

SQL Server Backups

In SQL Server, backups are necessary to protect data and ensure recovery in the event of a failure or disaster. There are many backup options, each serving a different purpose. 

Types of SQL Database Backups

Here are the three main types of SQL database backups are given,

Full Backup

  • A full backup takes the entire database at a specified time, including all data and objects.
    It is the basis for other types of backups and it is important to restore the state of the database during a backup.
  • Generally, full backups are scheduled regularly to ensure comprehensive data protection.

Example- 

  1. Backup using SQL Query

SQL Query BACKUP DATABASE is used to take the database backup,

USE [YourDatabaseName]
GO
BACKUP DATABASE [YourDatabaseName]
TO DISK = 'D:\Users\Database BackUp\mindstickdb\YourDatabaseName.bak';

In the example above

  • don't forget to replace the [YourDatabaseName] with your actual database name.
  • add appropriate file location in your system
  • don't forget to add file extension .bak with your database name.

 

  2. using SQL Server Management System (SSMS)

Follow the given steps to backup the SQL Database using SSMS,

Step-1 Open and login in to SSMS

step-2 Right click on the database name which you want to backup and select the Task option and then Back Up... as given in the below picture,

 

Explain the SQL Server backups and their types

 

Step- 3 A new window will open in which some options are need to select like, Database: DatabaseName, Backup Type: Full, Backup Component: Database (default selected), and Back up to: Disk as the given below in the picture, 

Explain the SQL Server backups and their types

 

Step- 4   Now, you need to add a specific folder location after click on Add button with file name with extension .bak in your system to save the database backup file as given below in the picture,

Explain the SQL Server backups and their types

Step- 5  Now click OK button to take the backup of your database like given below,

Explain the SQL Server backups and their types

Step- 6  The response will come when the database backup successfully

Explain the SQL Server backups and their types


Differential Backup

  • A differential backup retrieves only data that has changed since the last full backup.
  • It reduces the time and space required compared to a full backup, speeding up build and recovery.
  • Useful for situations where full backups are often impractical due to database sizes or time constraints.

Example-

To create a differential backup, you use the BACKUP DATABASE statement with the DIFFERENTIAL option as follows,

USE database_name
GO;
BACKUP DATABASE database_name 
TO DISK = path_to_backup_file 
WITH DIFFERENTIAL;

Transaction Log Backup

  • Transaction log backups capture all transaction log records created since the last transaction log backup.
  • Recovery is allowed for a certain period of time, known as seasonal relief.
  • They are required to ensure minimal data loss when a failure occurs or maintain a standby server for disaster recovery.

Example-

To create a transaction log backup, you use the BACKUP LOG statement.

BACKUP LOG database_name 
TO DISK = path_to_backup_file 
WITH options;

 

Each backup type serves a specific purpose to ensure the integrity and recoverability of SQL Server databases. Effective backup strategies typically combine these types based on database size, recovery needs, and performance requirements to ensure complete data protection and downtime in the event of a failure the work is limited.

 

Also, Read: How do I use CTE to simplify complex queries in SQL Server?


Updated 05-Jul-2024
Hi! This is Ashutosh Kumar Verma. I am a software developer at MindStick Software Pvt Ltd since 2021. I have added some new and interesting features to the MindStick website like a story section, audio section, and merge profile feature on MindStick subdomains, etc. I love coding and I have good knowledge of SQL Database.

Leave Comment

Comments

Liked By